import {Injectable} from '@angular/core';
import {HttpServicesProvider} from "../http-services/http-services";
import {ConfigProvider} from "../config/config";
import {StorageProvider} from "../storage/storage";

@Injectable()
export class CommonProvider {

    constructor(
        public http: HttpServicesProvider,
        public config: ConfigProvider,
        public storage: StorageProvider
    ) {

    }


    /**
     * 收藏信息/任务功能
     * */
    public collect(amoy_id,callback){
        let apiUrl = "/task_info/collect_option";
        this.http.requestPostData(apiUrl, {
            token: this.config.getToken(),
            amoy_id: amoy_id,
            type: 1
        },response => {
            callback(response);
        });
    }

    /**
     * 点赞信息/任务功能
     * */
    public like(amoy_id,callback){
        let apiUrl = "/task_info/collect_option";
        this.http.requestPostData(apiUrl, {
            token: this.config.getToken(),
            amoy_id: amoy_id,
            type: 2
        },response => {
            callback(response);
        });
    }

    /**
     * 设置跳转返回处理
     * */
    public setBackPage(page, params){
        this.storage.set('backPage', JSON.stringify({page: page, params: params}));
    }

    /**
     * 获取跳转返回地址
     * */
    public getBackPage(){
        let backPage = this.storage.get('backPage');
        if(backPage){
            return JSON.parse(backPage);
        }else{
            return false;
        }
    }
}
